package org.easy.tool.controller;

import org.easy.tool.common.R;
import org.easy.tool.entity.Knowledge;
import org.easy.tool.service.IKnowledge;
import org.easy.tool.service.IProblem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * 处理题目
 *
 * @author Valley
 * @since 2024-09-04 22:51:14
 */
@RestController
@RequestMapping("/problem")
public class ProblemController {

    @Autowired
    IProblem service;

    @Autowired
    IKnowledge knowledgeService;


    @RequestMapping("submitProblem")
    public R submitProblem(@RequestBody(required = false) LinkedHashMap data) throws Exception {
        return R.ok(service.submitProblem(data));
    }

    @RequestMapping("getProblemList")
    public R getProblemList(@RequestBody(required = false) LinkedHashMap data) throws Exception {
        return R.ok(service.getProblemList(data));
    }

    @RequestMapping("getPageProblemList")
    public R getPageProblemList(@RequestBody(required = false)LinkedHashMap data) throws Exception {
        List<String> tags = (List<String>) data.get("tags");
        List<List<String>> knowledgeSet = new ArrayList<>();
        for (String knowledgeId : tags) {
            List<String> allKnowledgeId = knowledgeService.getAllKnowledgeId(knowledgeId);
            knowledgeSet.add(allKnowledgeId);
        }
        return R.ok(service.getPageProblemList(data, knowledgeSet));
    }

    @RequestMapping("deleteProblem")
    public R deleteProblem(@RequestBody(required = false) LinkedHashMap data) throws Exception {
        return R.ok(service.deleteProblem(data));
    }

    @RequestMapping("createEasyProblem")
    public R createEasyProblem(@RequestBody(required = false) LinkedHashMap data) throws Exception {
        return R.ok(service.createEasyProblem(data));
    }

    @RequestMapping("getEasyProblem")
    public R getEasyProblem(@RequestBody(required = false) LinkedHashMap data) throws Exception {
        return R.ok(service.getEasyProblem(data));
    }



}
